﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.复习八月份
{
    public class Solution17
    {

        IList<string> res;

        Dictionary<char, string> dic;
        public IList<string> LetterCombinations(string digits)
        {
            res = new List<string>();


            if (digits.Length == 0)
            {
                return res;
            }


            dic = new Dictionary<char, string>();
            dic.Add('2', "abc");
            dic.Add('3', "def");

            dic.Add('4', "ghi");
            dic.Add('5', "jkl");
            dic.Add('6', "mno");
            dic.Add('7', "pqrs");
            dic.Add('8', "tuv");
            dic.Add('9', "wxyz");
            IList<string> strings = new List<string>();
            IList<char> path = new List<char>();



            DFS(path, digits, 0);
            return res;
        }

        void DFS(IList<char> path, string digits, int cur)
        {

            if (path.Count == digits.Length)
            {
                string curRes = "";
                for (int i = 0; i < path.Count; i++)
                {
                    curRes += path[i];
                }
                res.Add(curRes);
                return;

            }
            char c = digits[cur];
            string curStr = dic[c];

            for (int i = 0; i < curStr.Length; i++)
            {
                path.Add(curStr[i]);
                DFS(path, digits, cur + 1);
                path.RemoveAt(path.Count - 1);
            }

        }



    }

    class Program17
    {
        static void Main17(string[] args)
        {

            Solution17 solution = new Solution17();
            string digits = "23";
            IList<string> res = solution.LetterCombinations(digits);
            for (int i = 0;i < res.Count;i++)
            {
                Console.Write(res[i]+",");
            }
            Console.WriteLine();
        }
    }
}
